<template>
  <div class="randoms-container">
    <el-card class="box-card">
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="关键字">
          <el-input
            class="randomsSearch"
            v-model="QueryInfo.keyword"
          ></el-input>
        </el-form-item>
        <el-row>
          <el-button size="medium" @click="clearSearchContent">清除</el-button>
          <el-button size="medium" type="primary" @click="getRandomsList"
            >搜索</el-button
          >
        </el-row>
      </el-form>

      <div class="pageSum">
        <i class="el-icon-info"></i>&nbsp;&nbsp;数据一共{{ total }}条
      </div>

      <el-table :data="randomsList.items" style="width: 100%">
        <el-table-column label="编号" width="230">
          <template slot-scope="scope">
            <span style="margin-left: 10px">{{ scope.row.id }}</span>
          </template>
        </el-table-column>
        <el-table-column label="题型" width="100">
          <template slot-scope="scope">
            <span
              style="margin-left: 10px"
              v-if="scope.row.questionType === '1'"
              >单选</span
            >
            <span
              style="margin-left: 10px"
              v-else-if="scope.row.questionType === '2'"
              >多选</span
            >
            <span style="margin-left: 10px" v-else>简答</span>
          </template>
        </el-table-column>
        <el-table-column label="题目编号" width="200">
          <template slot-scope="scope">
            <span
              style="margin-left: 10px; color: blue"
              v-for="(item, id) in scope.row.questionIDs"
              :key="id"
            >
              <a @click="onNumber(item)">{{ item.number }}</a>
            </span>
          </template>
        </el-table-column>
        <el-table-column label="录入时间" width="200">
          <template slot-scope="scope">
            <span style="margin-left: 10px">{{ scope.row.addTime }}</span>
          </template>
        </el-table-column>
        <el-table-column label="答题时间(s)" width="145">
          <template slot-scope="scope">
            <span style="margin-left: 10px">{{ scope.row.totalSeconds }}</span>
          </template>
        </el-table-column>
        <el-table-column label="正确率(%)" width="145">
          <template slot-scope="scope">
            <span style="margin-left: 10px">{{ scope.row.accuracyRate }}</span>
          </template>
        </el-table-column>
        <el-table-column label="录入人" width="145">
          <template slot-scope="scope">
            <span style="margin-left: 10px">{{ scope.row.userName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
              class="btn-d"
              icon="el-icon-delete"
              size="mini"
              circle
              @click="deleteItem(scope.row)"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>

      <div class="container">
        <el-dialog
          class="dialog-table"
          width="800px"
          title="题目预览"
          :visible.sync="dialogVisible"
        >
          <el-row :gutter="20" class="tixing">
            <el-col :span="6"
              >【题型】：
              <span v-if="parseInt(dialogTable.questionType) === 1">单选</span>
              <span v-else-if="parseInt(dialogTable.questionType) === 2"
                >多选</span
              >
              <span v-else-if="parseInt(dialogTable.questionType) === 3"
                >简答</span
              >
            </el-col>
            <el-col :span="6">【编号】：{{ dialogTable.id }}</el-col>
            <el-col :span="6"
              >【难度】：
              <span v-if="parseInt(dialogTable.questionType) === 1">简单</span>
              <span v-else-if="parseInt(dialogTable.questionType) === 2"
                >一般</span
              >
              <span v-else-if="parseInt(dialogTable.questionType) === 3"
                >困难</span
              >
            </el-col>
            <el-col :span="6">【标签】：{{ dialogTable.tags }}</el-col>
            <div class="timu">
              <el-col :span="6">【学科】：{{ dialogTable.subjectName }}</el-col>
              <el-col :span="6"
                >【目录】：{{ dialogTable.directoryName }}</el-col
              >
              <el-col :span="6">【方向】：{{ dialogTable.direction }}</el-col>
            </div>
          </el-row>

          <el-row :gutter="20" class="namessss">
            <span class="tigan">【题干】：</span>
            <span class="tigan" v-html="dialogTable.question"></span>
          </el-row>

          <el-row :gutter="20">
            <span class="cankao">【参考答案】：</span>
            <a
              ><span
                class="cankaoBtn"
                @click="isVideoShow()"
                size="mini"
                type="danger"
              >
                视频解析
              </span></a
            >

            <div>
              <video
                v-show="this.videoShow"
                height="200px"
                controls="controls"
                :src="dialogTable.videoURL"
              ></video>
            </div>
          </el-row>
          <el-row class="anwser" :gutter="20">
            <span class="daan">【答案解析】：</span>
            <span v-html="dialogTable.answer"></span>
          </el-row>

          <el-row :gutter="20">
            <span class="tmubeizhu">【题目备注】：</span>
            <span v-html="dialogTable.remarks"></span>
          </el-row>

          <div class="dialog-table-btn">
            <el-button type="primary" @click="isDialogVisible">
              关闭
            </el-button>
          </div>
        </el-dialog>
      </div>

      <div class="randomsPage">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="QueryInfo.page"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="QueryInfo.pagesize"
          layout=" sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </div>
    </el-card>
  </div>
</template>

<script>
import { detail, randoms, removeRandoms } from "@/api/hmmm/questions";
export default {
  name: "questionsRandoms",
  data() {
    return {
      dialogTable: {
        type: [Number, String, Object, Array],
        required: true,
      },

      randomsList: [],
      form: {
        searchContent: "",
      },
      dialogVisible: false,
      videoShow: false,
      total: 0,
      QueryInfo: {
        pagesize: 20,
        page: 1,
        keyword: "",
      },
    };
  },
  created() {
    this.getRandomsList();
  },
  methods: {
    clearSearchContent() {
      this.QueryInfo.keyword = "";
      this.getRandomsList();
    },
    handleSizeChange(newSize) {
      this.QueryInfo.pagesize = newSize;
      this.getRandomsList();
    },
    handleCurrentChange(newPage) {
      this.QueryInfo.page = newPage;
      this.getRandomsList();
    },
    async getRandomsList() {
      const { data } = await randoms(this.QueryInfo);
      this.randomsList = data;
      this.items = this.randomsList.items;
      this.total = data.counts;
    },
    async deleteItem(id) {
      const confirmResult = await this.$confirm("是否删除数据？", {
        confirmButtonText: "取消",
        confirmButtonText: "确定",
        type: "warning",
      }).catch((err) => err);
      if (confirmResult !== "confirm") {
        return this.$message.info("取消了删除");
      }
      removeRandoms(id);
      this.getRandomsList();
      return this.$message.info("删除了数据");
    },
    async onNumber(item) {
      this.dialogVisible = true;
      const { data: res } = await detail(item);
      this.dialogTable = res;
      console.log(res);
    },
    isVideoShow() {
      this.videoShow = !this.videoShow;
    },
    isDialogVisible() {
      this.dialogVisible = false;
    },
  },
};
</script>

<style scoped lang='less'>
.randoms-container {
  overflow-x: hidden;

  .box-card {
    width: 100%;
    margin: 20px 14px;
    overflow-x: hidden;
    /deep/ .el-row {
      padding: 16px 0;
      border-top: 2px solid rgb(197, 191, 191);
    }
    /deep/ .el-row:nth-child(1) {
      border-top: none;
    }
    .pageSum {
      padding-left: 24px;
      height: 44px;
      line-height: 44px;
      color: #9d9f99;
      background: #f4f4f5;
    }
    .el-form {
      display: flex;
      justify-content: space-between;
    }
    .el-form {
      height: 40px;
    }
    .randomsSearch {
      width: 304px;
    }
    .randomsPage {
      float: right;
    }
    /deep/.btn-d {
      background-color: #fef0f0;
      color: red;
      border: 1px soild red;
    }
    /deep/.dialog-table-btn {
      text-align: center;
    }
    /deep/.anwser {
      margin: 10px;
    }
    span.cankaoBtn {
      padding: 8px 12px;
      color: #fff;
      background: rgb(245, 108, 108);
    }
  }
}
</style>
